//
//  GMlevelView.m
//  Teecloud
//
//  Created by 小熊 on 2018/10/26.
//  Copyright © 2018年 小志. All rights reserved.
//

#import "GMlevelView.h"

@implementation GMlevelView

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super initWithCoder:aDecoder]) {
//        self.CrownCount=1;
//        self.SunCount =2;
//        self.MoonCount=3;
//        self.StarCount =4;
//        [self createlevelView];
    }
    return self;
}

#pragma mark 代理方式

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
  
//        [self createlevelView];
    }
    return self;
}
//-(void)setCrownCount:(NSInteger)CrownCount{
//    _CrownCount = CrownCount;
//    [self createlevelView];
//}
//-(void)setSunCount:(NSInteger)SunCount{
//    _SunCount = SunCount;
//     [self createlevelView];
//}
//-(void)setMoonCount:(NSInteger)MoonCount{
//    _MoonCount =MoonCount;
//    [self createlevelView];
//}
//-(void)setStarCount:(NSInteger)StarCount{
//    _StarCount = StarCount;
//    [self createlevelView];
//}
//-(void)createlevelView{
//    for (NSInteger i =0; i<self.CrownCount; i++) {
//        UIImageView *imgView =[[UIImageView alloc] initWithFrame:CGRectMake(i*20, 2.5, 20,20)];
//        imgView.image =[UIImage imageNamed:@"crown-32"];
//        [self addSubview:imgView];
//    }
//    for (NSInteger i=0; i<self.SunCount; i++) {
//        UIImageView *imgView =[[UIImageView alloc] initWithFrame:CGRectMake(20*self.CrownCount+i*20, 2.5, 20,20)];
//        imgView.image =[UIImage imageNamed:@"sun-32"];
//        [self addSubview:imgView];
//    }
//    for (NSInteger i=0; i<self.MoonCount; i++) {
//        UIImageView *imgView =[[UIImageView alloc] initWithFrame:CGRectMake(20*(self.CrownCount+self.SunCount)+i*20, 2.5, 20,20)];
//        imgView.image =[UIImage imageNamed:@"moon-32"];
//        [self addSubview:imgView];
//    }
//    for (NSInteger i=0; i<self.StarCount; i++) {
//        UIImageView *imgView =[[UIImageView alloc] initWithFrame:CGRectMake(20*(self.CrownCount+self.SunCount+self.MoonCount)+i*20, 2.5, 20,20)];
//        imgView.image =[UIImage imageNamed:@"star-32"];
//        [self addSubview:imgView];
//    }
//}
-(void)setCrownCount:(NSInteger)CrownCount SunCount:(NSInteger)SunCount MoonCount:(NSInteger)MoonCount StarCount:(NSInteger)StarCount{
    //依次遍历self.view中的所有子视图
    for(id tmpView in [self subviews]){
        //找到要删除的子视图的对象
        if([tmpView isKindOfClass:[UIImageView class]]){
            UIImageView *imgView = (UIImageView *)tmpView;
                [imgView removeFromSuperview]; //删除子视图
            }
    }
    for (NSInteger i =0; i<CrownCount; i++) {
        UIImageView *imgView =[[UIImageView alloc] initWithFrame:CGRectMake(i*20, 2.5, 20,20)];
        imgView.image =[UIImage imageNamed:@"crown-32"];
        [self addSubview:imgView];
    }
    for (NSInteger i=0; i<SunCount; i++) {
        UIImageView *imgView =[[UIImageView alloc] initWithFrame:CGRectMake(20*CrownCount+i*20, 2.5, 20,20)];
        imgView.image =[UIImage imageNamed:@"sun-32"];
        [self addSubview:imgView];
    }
    for (NSInteger i=0; i<MoonCount; i++) {
        UIImageView *imgView =[[UIImageView alloc] initWithFrame:CGRectMake(20*(CrownCount+SunCount)+i*20, 2.5, 20,20)];
        imgView.image =[UIImage imageNamed:@"moon-32"];
        [self addSubview:imgView];
    }
    for (NSInteger i=0; i<StarCount; i++) {
        UIImageView *imgView =[[UIImageView alloc] initWithFrame:CGRectMake(20*(CrownCount+SunCount+MoonCount)+i*20, 2.5, 20,20)];
        imgView.image =[UIImage imageNamed:@"star-32"];
        [self addSubview:imgView];
    }
}

@end

